<?php
class MW_Simplenews_Block_Adminhtml_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
	 public function __construct()
	 {
		 parent::__construct();
		 $this->setId('categoryGrid');
		 $this->setDefaultSort('id');
		 $this->setDefaultDir('ASC');
		 $this->setSaveParametersInSession(true);
	 }
	 
	 /**
	 * lay ra collection can hien thi len grid
	 */
	 protected function _prepareCollection()
	 {	
		 $collection = Mage::getModel('simplenews/category')->getCollection();
		 $this->setCollection($collection);
		 return parent::_prepareCollection();
	 }
	 
	 /**
	 * hàm chuẩn bị trước khi in ra grid
	 */
	 protected function _prepareColumns()
	 {
	 	$this->addColumn('id', array(
			 'header' => Mage::helper('simplenews')->__('ID'),
			 'align' =>'right',
			 'width' => '50px',
			 'index' => 'id',
		 ));
		 
		$this->addColumn('title', array(
		 'header' => Mage::helper('simplenews')->__('Title'),
		 'align' =>'left',
		 'index' => 'title',
		 ));
		 
		$this->addColumn('store_view', array(
		 'header' => Mage::helper('simplenews')->__('Store View'),
		 'align' =>'left',
		 'index' => 'store_view',
		 ));

		$this->addColumn('description', array(
		 'header' => Mage::helper('simplenews')->__('Description'),
		 'align' =>'left',
		 'index' => 'description',
		 ));
		 
		$this->addColumn('status', array(
		 'header' => Mage::helper('simplenews')->__('Status'),
		 'align' => 'left',
		 'width' => '80px',
		 'index' => 'status',
		 'type' => 'options',
		 'options' => array(
			 1 => 'Enabled',
			 2 => 'Disabled',
			 ),
		 ));
		 
		return parent::_prepareColumns();
	 }
	 
	 /**
	 * hàm trả lại url cho mỗi row trong grid
	 */
	 public function getRowUrl($row)
	  {
	      return $this->getUrl('*/*/edit', array('id' => $row->getId()));
	  }
}